1. Technical Field
The present invention relates generally to an improved data processing system and in particular to an improved method and apparatus for executing instructions in a data processing system. Still more particularly, the present invention relates to a method and apparatus for improving invocation speed of Java methods in a data processing system.
2. Description of Related Art
Java is an object oriented programming language and environment focusing on defining data as objects and the methods that may be applied to those objects. xe2x80x9cJavaxe2x80x9d is a trademark of Sun Microsystems, Inc. Java supports only a single inheritance, meaning that each class can inherit from only one other class at any given time. Java also allows for the creation of totally abstract classes known as interfaces, which allow the defining of methods that may be shared with several classes without regard for how other classes are handling the methods. Java provides a mechanism to distribute software to different computing platforms.
Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating system architectures. The Java Virtual Machine (JVM) is a virtual computer component that resides only in memory. The JVM allows Java programs to be executed on different platforms as opposed to only the one platform for which the code was compiled. Java programs are compiled for the JVM. In this manner, Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating systems architectures. To enable a Java application to execute on different types of data processing systems, a compiler typically generates an architecture-neutral file format. The compiled code is executable on many processors, given the presence of the Java runtime system. The Java compiler generates bytecode instructions that are non-specific to particular computer architectures. A bytecode is a machine independent code generated by the Java compiler and executed by a Java interpreter. A Java interpreter is a module in the JVM that alternatively decodes and executes a bytecode or bytecodes. These bytecode instructions are designed to be easy to interpret on any machine and easily translated on the fly into native machine code.
A development environment, such as the Java Development Kit (JDK), available from Sun Microsystems, Inc., may be used to build Java bytecode from Java language source code and libraries. This Java bytecode may be stored as a Java application or applet on a Web Server, where it can be downloaded over a network to a user""s machine and executed on a local JVM.
When extra speed in executing a Java program is needed, a Just In Time (JIT) compiler may be used to translate bytecodes for a method or class into native machine instructions before executing them. Typically, this compilation only occurs once per method. Some JIT compilers may compile entire classes, rather than one method at a time.
When a JVM interpreter encounters an invoke bytecode, the JVM interpreter locates the appropriate method to be called and then calls the method. This calling of the method may be performed by locating a method block and branching to the invoker for the method. The method block identifies the invoker and is a per method data structure. The invoker performs the function activation and creates a stack frame for the target method. This process performed by the invoker involves ensuring that parameters are passed appropriately to the target method. A monitor, also referred to as a lock, is obtained by the invoker if the method is synchronized. Other housekeeping chores may be involved based on the particular target method.
When the JVM interpreter encounters a return bytecode, signaling method completion, a complimentary set of housekeeping chores must be performed to deactivate the function, release the stack frame, release the monitor if acquired, and properly return the result to the caller. The standard JVM implementation from Sun Microsystems, Inc. provides invokers for synchronized and non-synchronized methods. However, the return bytecodes, which return to the calling method directly, have no such specialization and must check the characteristics of the calling methods to properly complete the return. Furthermore, the invokers may be required to set flags that are subsequently examined by the return bytecodes in presently available JVM implementations.
The current implementation of JVM""s only employs invokers, which have limited specialization and generalized return bytecodes, which must perform runtime checks to determine which tasks must be performed during function activation/deactivation. Function activation is all the steps necessary to properly call a method. It includes passing the parameters on the stack, setting up the stack frame with any values required by the method (e.g. a pointer to the method block for the called method), storing the return address to which control should be transferred when the method competes and acquiring the object monitor if the method is synchronized. This data structure on the stack is referred to as the function activation record. Function deactivation is all the steps necessary to terminate a method call. It includes releasing the stack frame for the method call, releasing the object monitor if the method is synchronized, removing the passed parameters from the stack and placing the called methods return value, if any, on the calling method""s stack. When function deactivation is complete, the function activation record for the called method has been removed from the stack. Such a procedure has a negative performance impact.
Therefore, it would be advantageous to have a method and apparatus for invoking methods in a fashion that eliminates the need for runtime decisions based on method characteristics.
The present invention provides a method and apparatus for executing a method. A bytecode invoking a method is detected. A method block is located associated with the method, wherein the method block includes an identification of an invoker. The invoker is called, wherein the invoker performs setup for execution of the method. The setup performed by the invoker is tailored specifically to the method. A completion of the method is detected and returns control to the invoker, wherein the invoker completes processing of the method.